﻿using XamlCleaner.Core.Loader;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;

namespace XamlCleaner.Core.Test
{
    
    
    /// <summary>
    ///This is a test class for XamlLoaderTest and is intended
    ///to contain all XamlLoaderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class XamlLoaderTest
    {

        string path = @"C:\Users\Miguel\Documents\Visual Studio 2010\Projects\CodePlex\XamlCleaner\XamlCleaner.Core.Test\bin\Debug\";
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        [TestInitialize()]
        public void MyTestInitialize()
        {            
            System.IO.File.Copy(string.Format("{0}OriginalTest.xaml",path),
                string.Format("{0}Test.xaml",path),true); 
        }
        
        //Use TestCleanup to run code after each test has run
        [TestCleanup()]
        public void MyTestCleanup()
        {
            System.IO.File.Delete(string.Format("{0}Test.xaml", path));
        }
        
        #endregion


        /// <summary> 
        ///A test for XamlLoader Constructor
        ///</summary>
        [TestMethod()]
        public void XmlLoader_Document_Return_Not_Null_When_string_right()
        {
            string filePath = string.Format("{0}Test.xaml", path); // TODO: Initialize to an appropriate value
            XamlLoader target = new XamlLoader(filePath);
            Assert.IsNotNull(target.Document);
            target.Dispose();
        }

        /// <summary> 
        ///A test for XamlLoader Constructor
        ///</summary>
        [TestMethod()]
        public void XmlLoader_Document_Return_Null_When_Path_Fails()
        {
            string filePath = string.Format("{0}TestBAD.xaml", path); // TODO: Initialize to an appropriate value
            XamlLoader target = new XamlLoader(filePath);
            Assert.IsNull(target.Document);
            target.Dispose();
        }

        /// <summary>
        ///A test for XamlLoader Constructor
        ///</summary>
        [TestMethod()]
        public void XmlLoader_Document_Return_Not_Null_When_TextReader_right()
        {
            string filePath = string.Format("{0}Test.xaml", path); // TODO: Initialize to an appropriate value
            TextReader tr = new StreamReader(filePath);
            XamlLoader target = new XamlLoader(tr);
            Assert.IsNotNull(target.Document);
            tr.Dispose();
            target.Dispose();
        }
    }
}
